#author: Piotr Falandysz

from graph import Graph
from dijkstra import *
import time
import platform

graph = Graph()
graph.load_from_file("dane.txt")

print "\nWitamy w Mini Nawigacji."

time.sleep(1)

exit = False
while exit != True:
	start = raw_input("\nPodaj miasto poczatkowe: ")
	while start not in graph.graph.keys():
		print "\nBrak takiego miasta w tej nawigacji"
		start = raw_input("Podaj miasto poczatkowe: ")
		
	end = raw_input("Podaj miasto docelowe: ")
	while end not in graph.graph.keys():
		print "\nBrak takiego miasta w tej nawigacji"
		end = raw_input("Podaj miasto docelowe: ")

	print "\nWyznaczam trase ..."
	time.sleep(2)

	distance, predecessor = Dijkstra(graph.graph, start, end)

	print "\nTrasa: " + start + " - " + end + " (" + str(distance) + " km)"
	print getPath(predecessor, end)
	
	if platform.system() == "Windows":
		from msvcrt import getch
		print "\nESC - wyjscie, ENTER - nowe wyszukiwanie"
		
		action = getch()
		while (ord(action) != 27 and ord(action) != 13):
			action = getch()
			
		if ord(action) == 27:
			exit = True
		elif ord(action) == 13:
			exit = False
	else:
		msg = "\nProsze wpisac: 'koniec' - wyjscie, 'nowe' - nowe wyszukiwanie: "
		action = raw_input(msg)
		while (action != "koniec" and action != "nowe"):
			action = raw_input(msg)
			
		if action == "koniec":
			exit = True
		elif action == "nowe":
			exit = False
	
print "\nDziekujemy za skorzystanie z Mini Nawigacji :)"